package com.joe.updemo.http.loader;

import com.google.gson.JsonObject;
import com.joe.updemo.http.dataStructure.BasicResponse;
import com.joe.updemo.http.dataStructure.JsonParams;
import com.joe.updemo.http.retrofit.RetrofitServiceManager;
import com.joe.updemo.http.service.ApiInterface;
import io.reactivex.Observable;

/**
 * Description:
 * File: ApiLoader.java
 * Author: Administrator
 * Create: 2018/07/30 09:34
 */
public class ApiLoader extends ObjectLoader {
    private ApiInterface apiInterface;

    public ApiLoader() {
        apiInterface = RetrofitServiceManager.getInstance().create(ApiInterface.class);
    }

    /**
     * post
     *
     * @param api    String
     * @param params params
     * @return Observable
     */
    public Observable<BasicResponse<JsonObject>> postHttpObserve(String api, JsonParams params) {
        return observe(apiInterface.post(api, params.buildRequestBody()));
    }

    /**
     * post
     *
     * @param api    String
     * @param params params
     * @return Observable
     */
    public Observable<BasicResponse<JsonObject>> getHttpObserve(String api, JsonParams params) {
        return observe(apiInterface.get(api, params));
    }

}
